import path from "node:path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";
import PostcssPxToViewport from "postcss-px-to-viewport-8-plugin";

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [VantResolver()],
      dts: "src/types/auto-imports.d.ts",
    }),
    Components({
      resolvers: [VantResolver()],
      dts: "src/types/auto-components.d.ts",
    }),
  ],
  css: {
    postcss: {
      plugins: [
        // PostcssPxToViewport({
        //   viewportWidth: 375,
        //   unitPrecision: 6,
        //   propList: ["*"],
        //   minPixelValue: 1,
        //   replace: true,
        // }),
      ],
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  server: {
    proxy: {
      "/api": {
        target: "http://8.137.121.26:8080/",
        // target: "http://127.0.0.1:8080/",
        changeOrigin: true,
        rewrite: (path) => path.replace("/api", ""),
      },
    },
  },
});
